#!/bin/bash
set -e
set -x
MYDIR="${0%/*}"
cd "$MYDIR/.."
source "recipes/common.sh"


# RECIPE START glibc
# depends: Python-native

reset_mtime glibc glibc/configure.ac
mkdir -p build/glibc
cd build/glibc
export CFLAGS='-O2 -g'
unset CPPFLAGS
unset LDFLAGS
../../glibc/configure \
	--target=$TARGET \
	${CONFIGURE_ARGS} \
	--with-headers=`pwd`/../../kernel-headers/${LINUX_ARCH}/usr/include \
	--disable-multilib \
        --disable-werror \
	--disable-crypt \
	libc_cv_forced_unwind=yes \
	${NIL}

cd ../..
make -j${JOBS} -C build/glibc

# Installing glibc into stage breaks further builds:
# libc.so is a linker script with absolute paths (i.e. /usr/lib64),
# and that script is not under the cross-toolchain sysroot, so
# (cross-)linker keeps these paths as is (which picks a native glibc).
# Therefore install stuff into a different directory
make -j${JOBS} -C build/glibc install DESTDIR="$rootfs"
wipe_la_files "$rootfs"
relocate_to_usr "$rootfs"

# install kernel headers
# ... but NOT into stage, use rootfs instead (to NOT break cross-glibc headers)
rsync -avcH ./kernel-headers/${LINUX_ARCH}/usr/include/ ${rootfs}${prefix}/include/

# RECIPE END glibc
